﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0207", Name = "文字栏检查_有记载但不是[文字記載あり]", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0207 : VerfityOneResult
    {
        /// <summary>
        /// 
        /// </summary>
        private bool _existString = true;

        /// <summary>
        ///         
        /// </summary>
        [Category("关键字:包含/不包含"), Description("（true:包含关键字,false:不包含关键字）")]
        public bool ExistString 
        {
            get { return _existString; }
            set { _existString = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private string _searchString = "文字記載あり";
        /// <summary>
        /// 
        /// </summary>
        [Category("查找字符串"), Description("多个字符串之间，以逗号分割")]
        [EditorAttribute(typeof(PropertyGridRichText), typeof(System.Drawing.Design.UITypeEditor))]
        public  string SearchString
        {
            get{return _searchString ;}
            set {_searchString =value ;}
        }

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;


            foreach (var rowResult in result)
            {

                foreach (var entryResult in rowResult)
                {
                    //结果全是 sting.empty 
                    //ex  "////" 不算
                    if (String.IsNullOrEmpty(entryResult.Replace("/", string.Empty)))
                    {
                        continue;
                    }

                    //找到录入结果中的 文字
                    var ss = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, entryResult).GetText();

                    bresult = ExistString ? exitsSecharchString(ss)
                        : !string.IsNullOrEmpty(ss) && !exitsSecharchString(ss);

                    if (bresult)
                    {
                        System.Console.WriteLine(ss);
                        break;
                       
                    }
                }

                if (bresult)
                    break;
            }

            if (bresult)
            {
                System.Console.WriteLine("VerfityRq0207");
            }

            return bresult;
        }

        private bool exitsSecharchString(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return false;
            }

            string[] searchStrs = this.SearchString.Split(new char[] { ','});
            foreach (string str in searchStrs)
            {
                if (text.Contains(str))
                    return true;
            }

            return false ;               
        }
    }
}
